package offer;

public class offer52 {
}
class Solution52 {
    public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
    if(headA==null||headB==null)
        return null;
    ListNode pA=headA,pB = headB;
    while (pA!=pB)
    {
        if(pA!=null)
        {
            pA = pA.next;
        }
        else if(pA==null)
        {
            pA = headB;
        }
       if(pB!=null)
        {
            pB = pB.next;
        }
        else if(pB==null)
        {
            pB = headA;
        }
    }
        return pA;
    }
}